USE [HomestayWebDB]
GO
/****** Object:  StoredProcedure [dbo].[Store_Likes_SelectTopPost]    Script Date: 11/26/2012 17:37:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
  
ALTER PROCEDURE [dbo].[Store_Likes_SelectTopPost]  
AS  
SELECT DISTINCT Post_ResultSearch_View.PostID
		,Post_ResultSearch_View.TimeCreated
		,Post_ResultSearch_View.Title
		,Post_ResultSearch_View.ProvinceID
		,Post_ResultSearch_View.Province
		,Post_ResultSearch_View.DistrictID
		,Post_ResultSearch_View.District
		,Post_ResultSearch_View.AvatarPost
		,Post_ResultSearch_View.AvatarUser
		,Post_ResultSearch_View.PricePerDay
		,Post_ResultSearch_View.PricePerWeek
		,Post_ResultSearch_View.PricePerMonth
		,Post_ResultSearch_View.PriceMin
		,Post_ResultSearch_View.PriceMax
		,Post_ResultSearch_View.PriceType
		,Post_ResultSearch_View.Area
		,Post_ResultSearch_View.AddressHouse
		,Post_ResultSearch_View.TypeOfHousesNAME
		,Post_ResultSearch_View.like_count
		,Post_ResultSearch_View.Username
		,Post_ResultSearch_View.HasGara
		,Post_ResultSearch_View.HasGarden
		,Post_ResultSearch_View.HasKitchen
		,TMP.numlike 
FROM Post_ResultSearch_View
		RIGHT JOIN (
				SELECT Top 10(COUNT(Likes.Username)) as numlike,Posts.PostID
				FROM Posts  
				RIGHT JOIN Likes ON (Posts.PostID=Likes.PostID)  
				GROUP BY Posts.PostID   
				) AS TMP ON (Post_ResultSearch_View.PostID = TMP.PostID)
